import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex) // vue的插件机制
import { getUser} from "@/api/index.js"
const store = new Vuex.Store({
	//数据
  state: {
    cheight: 0,
	userInfo:{
		userId:0,
		username:"",
		password:"",
		role:'',
		phone:""
	}
  },
  //get set
  mutations: {
    setCheightMutactions(state, payload) {
      state.cheight = payload;
    },
	setUserInfoMutactions(state, payload) {
	  state.userInfo = payload;
	}
  },
  //发送请求，commit提交，调用mutactions方法来修改state
  actions:{
	setCheightActions(context) {
		uni.getSystemInfo({
			success: function(res) {
				// *****高度宽度的单位都是px 
				console.log("windowHeight：",res.windowHeight)	
				context.commit('setCheightMutactions', res.windowHeight);
			}
		})
	},
	setUserInfoActions(context) {
		let options=['管理员','房东','租客']
		getUser().then(res=>{
			res.data.role=options[res.data.role-1]
			context.commit('setUserInfoMutactions',res.data);
		})
	}
  }
});


export default store;
